﻿using System.Text.RegularExpressions;

namespace ShopB2C.Helper
{
    public class ValidDataHelper
    {

        /// <summary>
        /// 验证不能为空
        /// </summary>
        /// <param name="input">输入字符串</param>
        /// <returns>如果值为空则返回false,反之返回ture</returns>
        public static bool Required(string input)
        {
            return !string.IsNullOrEmpty(input) && input.Trim().Length > 0;
        }
        /// <summary>
        /// 是否为Bool
        /// </summary>
        /// <param name="input">输入字符串</param>
        /// <returns>如果为Mail格式则返回True，反之则返回false</returns>
        public static bool IsEmail(string input)
        {
            input = input ?? string.Empty;
            return  Regex.IsMatch(input , @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" , RegexOptions.IgnoreCase | RegexOptions.Multiline);
        }
        /// <summary>
        /// 最小长度
        /// </summary>
        /// <param name="input">输入字符串</param>
        /// <param name="length">最小长度</param>
        /// <returns>如果输入字符串长度符合要求，返回ture,反之返回false</returns>
        public static bool MinLength(string input , int length)
        {
            return !string.IsNullOrEmpty(input) && input.Trim().Length >= length;
        }
        /// <summary>
        /// 字符串长度限定在范围内
        /// </summary>
        /// <param name="input">输入字符串</param>
        /// <param name="minLength">最小长度</param>
        /// <param name="maxLength">最大长度</param>
        /// <returns>是否在范围内</returns>
        public static bool StringLengthRange(string input , int minLength , int maxLength)
        {
            return !string.IsNullOrEmpty(input) && input.Trim().Length > minLength && input.Trim().Length < maxLength;
        }
        /// <summary>
        /// 数值范围类
        /// </summary>
        /// <param name="input">输入数值</param>
        /// <param name="minValue">最小值</param>
        /// <param name="maxValue">最大值</param>
        /// <returns>是否范围内</returns>
        public static bool Range(int input , int minValue , int maxValue)
        {
            return input > minValue && input < maxValue;
        }


    }
}
